﻿
Imports System.IO
Imports xmlctrl
Imports xhtmlctrl
Imports webctrl

Public Class whatsnew
    Inherits cacheControlProcessor

    Public Const _pathidentity As String = "/whatsnew"
    Public Const recentCategoryId As String = "nwst_rc"
    Public Const ajaxfailedTextVar As String = "waft"

    Public Overrides Function pathidentity() As String
        Return _pathidentity
    End Function

    Protected Overrides Function normalRetiredTicks() As Int64
        Return secondsToTicks(10)
    End Function

    Protected Overrides Function processImpl(ByVal context As httpContext, _
                                             ByRef control As xmlcontrol) As Boolean
        assert(Not context Is Nothing, "context is nothing.")
        If wfileis.recentTopic.processImpl(context, control) Then
            Dim page As xhtmlpage = Nothing
            page = convertor.cast(Of xhtmlpage)(control)
            page.title().text = context.string(stringId.WHATSNEW_TITLE)

            Dim rightrail As div = Nothing
            rightrail = context.createControl(New div())
            rightrail.id = "rgtrl"
            page.body().addchild(rightrail)

            Dim rchead As h4 = Nothing
            rchead = context.createControl(New h4())
            rchead.text = context.string(stringId.RECENT_CATEGORY_TITLE)
            rightrail.addchild(rchead)

            Dim rc As div = Nothing
            rc = context.createControl(New div())
            rc.id = recentCategoryId
            rightrail.addchild(rc)

            webctrl.var.invoke(page.inlineScript(), ajaxfailedTextVar, _
                               "'" + context.string(stringId.FAILEDGETCATEGORY) + "'")
            Dim a As emptyA = Nothing
            a = context.createControl(New emptyA())
            a.onclick = changeInnerHtmlByIdWithAjaxCall.invoke(page.inlineScript(), _
                                                               "'" + _
                                                                   recentCategory.generateRecentCategoryAjaxLink() + _
                                                               "'", _
                                                               "'" + recentCategoryId + "'", _
                                                               failedToGetResponseText:=ajaxfailedTextVar)
            a.text = context.string(stringId.WHATSNEW_RECENTCATEGORY)
            rc.addchild(a)

            Return True
        Else
            Return False
        End If
    End Function
End Class
